#include "platform.h"

	# size of each hart's stack is 1024 bytes(1KB)
	.equ	STACK_SIZE, 1024

	.global	_start

	.text
_start:
	# park harts with id != 0
	csrr	t0, mhartid		# 读当前 hart 的 ID（0,1,2,...）
	mv	tp, t0				# 把 hartid 存到 tp（线程指针寄存器），以后在 C/汇编里都能方便取到
	bnez	t0, park		# 如果不是 hart 0，则跳去“停车”等待中断

	# Setup stacks, the stack grows from bottom to top, so we put the
	# stack pointer to the very end of the stack range.
	slli	t0, t0, 10		# t0 <<= 10 等价 t0 *= 1024（与 STACK_SIZE 相同）
	la	sp, stacks + STACK_SIZE	# sp 指向第一个栈区的“末端/高地址”
	add	sp, sp, t0			# sp += hartid * 1024，定位到各自栈顶

	j	start_kernel		# hart 0 jump to c

park:
	wfi
	j	park

	# In the standard RISC-V calling convention, the stack pointer sp
	# is always 16-byte aligned.
.balign 16
stacks:
	.skip	STACK_SIZE * MAXNUM_CPU # allocate space for all the harts stacks

	.end				# End of file
